package com.teemo.equipment.domain.vo;

import com.teemo.equipment.enums.BizCodeEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

/**
 * @author Teemo
 */
@Data
public class ResultVO<T> {
    @Schema(description = "是否成功")
    private Boolean success;
    @Schema(description = "提示信息")
    private String message;
    @Schema(description = "业务编码")
    private Integer code;
    private T data;

    public static <T> ResultVO<T> success(T data) {
        ResultVO<T> resultVO = new ResultVO<>();
        resultVO.setSuccess(true);
        resultVO.setData(data);
        resultVO.setCode(BizCodeEnum.SUCCESS.getCode());
        return resultVO;
    }

    public static <T> ResultVO<T> success() {
        ResultVO<T> resultVO = new ResultVO<>();
        resultVO.setSuccess(true);
        resultVO.setCode(BizCodeEnum.SUCCESS.getCode());
        return resultVO;
    }

    public static <T> ResultVO<T> fail(T data) {
        ResultVO<T> resultVO = new ResultVO<>();
        resultVO.setSuccess(false);
        resultVO.setData(data);
        resultVO.setCode(BizCodeEnum.UNKNOWN_ERROR.getCode());
        return resultVO;
    }

    public static <T> ResultVO<T> fail() {
        ResultVO<T> resultVO = new ResultVO<>();
        resultVO.setSuccess(false);
        resultVO.setCode(BizCodeEnum.UNKNOWN_ERROR.getCode());
        return resultVO;
    }
}
